<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/common.jspf" %>
<html>
<head>
<title>My JSP 'MyJsp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

    <script type="text/javascript">
        $(function(){
            $('#updateTable').form("disableValidation");//禁用验证
                $('#updateTable').form('load',{
                tableNum:row.tableNum,
                tableUserPhone:row.tableUserPhone,
                tableStartTime:row.tableStartTime,
                tableEndTime:row.tableEndTime,
                tableCommon:row.tableCommon,
                tableUpdate:myformatter(new Date())
            });
            $('#nn').attr('readonly',true);
            checkPhone();
            checkDateTime();
            change();
        });

        var oldWin = parent.$("iframe[title='餐桌工作状态管理']").get(0).contentWindow;//返回ifram页面文档（window)
        var row =oldWin.$('#tableUser').datagrid("getSelected");
        //alert("获取原窗口："+row.tableNum+","+row.tableUserPhone+","+row.tableStartTime+","+row.tableEndTime+","+row.tableCommon);

        function change() {
            var v= $('#updateTable').combobox("getValue");
            alert(v);
            if (v == '用餐中'){
                $('#phone').attr('readonly',true);
                $('#starttime').attr('readonly',true);
                $('#endtime').attr('readonly',true);
            }
        }

        function  save() {
            $('#updateTable').form("enableValidation");//启用验证
            //提交表单
            $('#updateTable').form('submit',{
                url: '${proPath}/tableuser/updateTable.action',
                //成功后，提示成功信息
                success:function(data){
                    alert("修改成功");
                    // 关闭本页面
                    parent.$('#win').window('close');
                    //刷新原页面
                    oldWin.$('#tableUser').datagrid("reload");
                }

            });
        }

        function checkPhone() {
            $.extend($.fn.validatebox.defaults.rules, {
                phoneNum: { //验证手机号
                    validator: function(value, param){
                        return /^1[3-8]+\d{9}$/.test(value);
                    },
                    message: '请输入正确的手机号码'
                }
            });
        }

        function myformatter(date){
            var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
            var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0"
                + (date.getMonth() + 1);
            var hor = date.getHours();
            var min = date.getMinutes();
            var sec = date.getSeconds();
            return date.getFullYear() + '-' + month + '-' + day+" "+hor+":"+min+":"+sec;
        }

        function checkDateTime() {
            //验证开始时间小于结束时间
            $.extend($.fn.validatebox.defaults.rules, {
                end: {
                    validator: function (value, param) {
                        var startDate = $('#StartDate').datetimebox('getValue');
                        var startTmp = new Date(startDate.replace(/-/g, "/"));
                        //alert(startDate);
                        //alert(startTmp);
                        var endTmp = new Date(value.replace(/-/g, "/"));
                        //alert(endTmp);
                        return startTmp < endTmp;
                    },
                    message: '结束时间要大于开始时间！'
                }
            });
            //验证开始时间大于当前时间
            $.extend($.fn.validatebox.defaults.rules, {
                start: {
                    validator: function (value, param) {
                        var startDate2 = myformatter(new Date());
                        var startTmp2 = new Date(startDate2);
                        var endTmp2 = new Date(value);
                        /*alert(startDate2);
                         alert(startTmp2);
                         alert(endTmp2);*/
                        return startTmp2 <= endTmp2;
                    },
                    message: '开始时间要大于当前时间！'
                }
            });
        }

    </script>


<body>
<form id="updateTable"  >
    <div>
        <label >餐桌编号:</label>
        <input class="easyui-validatebox" type="text"  id="nn" name="tableNum" data-options="required:true" />
    </div>

    <div>
        <label >工作状态:</label>
        <select id="cc" class="easyui-combobox" name="tableWorkStatus" style="width:200px;">
            <option>已预订</option>
            <option>用餐中</option>
            <option>已使用完</option>
        </select>
    </div>

    <div>
        <label >手机号:</label>
        <%--<input class="easyui-validatebox" type="text" name="tableUserPhone" validtype="mobile" data-options="required:true"/>--%>
        <input class="easyui-validatebox" type="text" id="phone" name="tableUserPhone" validType="phoneNum" ata-options="required:true"/>
    </div>
    <div>
        预约开始时间:<div class="easyui-datetimebox" type="text" name="tableStartTime" id="StartDate" validType="start" data-options="required:true" style="height:26px;width:150px "></div>
    </div>
    <div>
        预约结束时间:<div class="easyui-datetimebox" type="text" name="tableEndTime" id="EndDate"  validType="end" data-options="required:true" style="height:26px;width:150px "></div>
    </div>
    <div>
        <label >备注:</label>
        <input class="easyui-validatebox" type="text" name="tableCommon"  />
    </div>
    <%--隐藏修改时间带到数据库--%>
    <div>
        <input class="easyui-validatebox" type="hidden" name="tableUpdate" />
    </div>
    <input type="button" onclick="save()" value="确定">
</form>
</body>
</html>